package com.xxkk.net.TcpNetty;

import com.ebo.synframework.nettybase.codec.ProtoDecoder;
import com.ebo.synframework.nettybase.codec.ProtoEncoder;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelUpstreamHandler;

import static org.jboss.netty.channel.Channels.pipeline;

/**
 * @author xxkk
 * @version 1.0.0
 * @title TcpSocketServerPiplineFactory
 * @description ʕ•ᴥ•ʔ
 * @create 2024/5/22 17:46
 **/
public class TcpServerPiplineFactory implements ChannelPipelineFactory {
    private ChannelUpstreamHandler upstreamHandler;

    public TcpServerPiplineFactory(ChannelUpstreamHandler upstreamHandler) {
        this.upstreamHandler = upstreamHandler;
    }

    @Override
    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = pipeline();
        pipeline.addLast("decoder", new ProtoDecoder());
        pipeline.addLast("encoder", new ProtoEncoder());
        pipeline.addLast("handler", upstreamHandler);
        return pipeline;
    }
}
